namespace SubSonic
{
    using System;
    using System.Collections.Generic;

    public static class CodeLanguageFactory
    {
        private static readonly List<ICodeLanguage> languages = new List<ICodeLanguage>();

        static CodeLanguageFactory()
        {
            languages.Add(new CSharpCodeLanguage());
            languages.Add(new VBCodeLanguage());
        }

        public static string AvoidKeyWord(string word, string table, string appendWith)
        {
            string str3;
            string str = word + appendWith;
            if (word.ToLower() == table)
            {
                return str;
            }
            if (((str3 = word.ToLower()) != null) && (str3 == "schema"))
            {
                return str;
            }
            foreach (ICodeLanguage language in languages)
            {
                if (language.IsKeyword(word))
                {
                    return str;
                }
            }
            return word;
        }

        public static ICodeLanguage GetByCodeProviderName(string providerName)
        {
            foreach (ICodeLanguage language in languages)
            {
                if (language.CodeProvider.Equals(providerName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return language;
                }
            }
            throw new ArgumentException("Unknown language", "providerName");
        }

        public static ICodeLanguage GetByShortName(string name)
        {
            foreach (ICodeLanguage language in languages)
            {
                if (language.ShortName.Equals(name, StringComparison.InvariantCultureIgnoreCase))
                {
                    return language;
                }
            }
            throw new ArgumentException("Unknown language", "name");
        }
    }
}

